<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <link rel="icon" href="<%= BASE_URL %>favicon.ico" />
    <title>
      <%= webpackConfig.name %>
    </title>
    <link rel="stylesheet" href="<%= BASE_URL %>static/css/loading.css" />
  </head>

  <body>
    <noscript>
      <strong
        >We're sorry but <%= webpackConfig.name %> doesn't work properly without
        JavaScript enabled. Please enable it to continue.</strong
      >
    </noscript>
    <div id="app">
      <div class="first-loading-wrp">
        <div class="loading-wrp">
          <span class="dot dot-spin">
            <i></i>
            <i></i>
            <i></i>
            <i></i>
          </span>
        </div>
        <h1><%= webpackConfig.name %></h1>
      </div>
    </div>
    <!-- built files will be auto injected -->
    <script>
      // 当 flutter 点击返回按钮的时候
      function allowBack(initUrl) {
        // 获取当前 url 与 initUrl 作比较
        const arr = window.location.href.split("/");
        const finalArr = arr[arr.length - 1].split("?");
        const arr2 = initUrl.split("/");
        const initArr = arr2[arr2.length - 1].split("?");
        if (finalArr[0] === initArr[0]) {
          console.log("当前页面已是webview最新页面，允许返回");
          // 调用flutter 的返回上级页面
          Flutter.postMessage("_back");
          return true;
        } else {
          console.log("当前页面并非webview最新页面，不允许返回");
          // webview 返回上一级页面即可
          goBack();
          return false;
        }
      }
      const goBack = () => {
        window.history.go(-1);
      };

      // html 页面需要获取token值的时候
      async function getToken() {
        const a = await Flutter.postMessage("_getToken");
      }

      // getToken()
      function saveToken(a) {
        // alert(a)
        window.localStorage.setItem("token", a);
      }
    </script>
  </body>
</html>
